var CestaVipOfertas = CestaVipMain.extend({
	initialize: function(param) {
		this._super();		
		this.idClass=3;	
		this.sTargetOffers = param;					//Id contenedor de la sección ofertas (se inicializa al instanciar el objeto)
		this.hideDiv='hideafterclick';
		this.showLoad = true;	//Show Loading Image
	   	//this.cssJsoned ="foo";
		this.limit=2;	//Number of new elements showed per click
		this.showLimit=2;	//Show Up to this number of elements
		this.current=0;	//Current number of elements showed

	},
	//Set current elements showed
	setCurrent: function(val){	
	   this.current=val;
	},
	getCurrent: function(){
	   return this.current;
	},
	//Get limit of elements for specified target (0 = Unlimited)
	getShowLimit: function(target){
	   if(target=='ofertas')
		   return this.showLimit;
	   else return 0;
	},
	//Increase the limit of elements allowed to show
	incShowLimit: function(target){
	   if(target=='ofertas'){
		this.showLimit=this.showLimit+this.limit;	//New limit= Current limit + elements per click
	   	//if(this.debug) console.log("Updated Limit:"+target+" New value:"+this.showLimit);
	   }
	},
	//This function will be called once all the elements have been shown limit = #total_elements
	endLimit: function(){	
		if($(this.hideDiv))
			$('#'+this.hideDiv).addClass("hidden");
	},
	//Get the mode to put the elements on the page (Push=Override, Add=Append)
	getMode: function(target){
		var m;
		switch (target){
			case 'headerBloquee':
				m="push";
				break;
			case 'ofertas':
				m="add";
				break;	
			default: m="push";
		}
	   return m;
        },
	/**
	 * Ofertas - Construye la pagina con los datos pasados por json previamente
	 */
	buildPage: function(generate) {
			switch(generate) {
					
				case 'block-ofertas':
					//INDEX, ofertas
					var data = this.getAjaxData();
					//Muestra sección de ofertas, si existen
					if ($(this.sTargetOffers) != null ) {	//Si existe el target donde se mostraran las ofertas
						this.showOffers(data, this.sTargetOffers);	//Mostrar capa (eliminar hidden de la clase)		
						//Generar html		
						this.htmlGenerate({	
							pushData: this.pushOffers,
							context: this
						});	
						//this.hideButton();
					}
					break;
				default:
					//Cualquier otro bloque, generar html estandar
					this.htmlGenerate();	
					break;
			}
	},
	//Show offers, unhide layer if there are elements
	showOffers: function (data, id) {
		//Si existe el objeto y contiene ofertas, se muestra.
		if ( !(typeof data.ofertas== "undefined") && (data.ofertas.length != 0) && ($('#'+id) != null)){
			$('#'+id).removeClass('hidden');
		
		}
	},
	// Modifies the jSON: setting showUrl=hidden to hide the LINK layer if there is no URL on jSON for this element
	showUrl: function(dataJson) {
	
		if( dataJson.url == "") {	//Si no hay url
			// ocultar capa con enlace
			if(this.debug) console.log ("Mostrando Unlinked-Layer para oferta:"+ dataJson.title);
			dataJson.showUrl = 'hidden';
		}
		return dataJson;
	},
	
	//Function called for each offer pushed, hides the LINK layer if there is nor url specified
	pushOffers: function (context, dataJson) {	
		
		return context.showUrl(dataJson);
	
	}
	

});

